'use strict';
exports.main = async (event, context) => {
  const db = uniCloud.database();
  const collection = db.collection('lipinka_xinghao_zhekou');
  
  // 检查是否已存在记录
  const existing = await collection.where({
    xinghao_id: event.xinghaoId,
    jingxiaoshang_id: event.jingxiaoshangId
  }).get();
  
  if (existing.data.length > 0) {
    // 更新已有记录
    await collection.doc(existing.data[0]._id).update({
      zhekou: event.zhekou,
      creat_time: new Date().toISOString()
    });
  } else {
    // 新增记录
    await collection.add({
      xinghao_id: event.xinghaoId,
      jingxiaoshang_id: event.jingxiaoshangId,
      zhekou: event.zhekou,
      creat_time: new Date().toISOString()
    });
  }
  
  return {
    success: true
  };
};
